<?php

namespace App\Http\Controllers\Admins;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admins\PermissionRequest;
use App\Repositories\BLL\PermissionBLL;
use Illuminate\Support\Facades\Route;

class PermissionController extends Controller
{
    private $permissionBLL;
	private $currentRouteName;
	  	

    function __construct(PermissionBLL $permission)
    {
    		$this->currentRouteName = Route::currentRouteName();
        $this->permissionBLL = $permission;
    }
	
    public function index()
    {
    		$addButton = sp_get_AddActionButton($this->currentRouteName);
        return view('admin.permission.index',
        					["addButton"=>$addButton]);
    }
	
	public function ajaxIndex()
    {
        $result = $this->permissionBLL->ajaxIndex($this->currentRouteName);
        return response()->json($result);
    }
	
	public function show($id)
    {
        $permission = $this->permissionBLL->editView($id);
        return view('admin.permission.show',
						["permission"=>$permission]);
    }
	
	public function create()
    {
        return view('admin.permission.create');
    }
	
	public function store(PermissionRequest $request)
    {
        $this->permissionBLL->createPermission($request->all());
        return redirect(route('permission.index'));
    }
	
	public function edit($id)
    {
        $permission = $this->permissionBLL->editView($id);
        return view('admin.permission.edit',
						["permission"=>$permission]);
    }

    public function update(PermissionRequest $request)
    {
        $this->permissionBLL->updatePermission($request->all());
        return redirect('admin/permission');
    }
	
    public function destroy($id)
    {
        $this->permissionBLL->destroyPermission($id);
        return redirect('admin/permission');
    }
	
}
